home *** CD-ROM | disk | FTP | other *** search
- #include "global.h"
- #include "mbuf.h"
- #include "internet.h"
- #include "ip.h"
- #include "icmp.h"
-
- /* Generate ICMP header in network byte order, link data, compute checksum */
- struct mbuf *
- htonicmp(icmp,data)
- struct icmp *icmp;
- struct mbuf *data;
- {
- struct mbuf *bp;
- register char *cp;
- int16 checksum;
-
- if((bp = pushdown(data,ICMPLEN)) == NULLBUF)
- return NULLBUF;
- cp = bp->data;
-
- *cp++ = icmp->type;
- *cp++ = icmp->code;
- cp = put16(cp,0); /* Clear checksum */
- cp = put16(cp,icmp->args.echo.id);
- cp = put16(cp,icmp->args.echo.seq);
-
- /* Compute checksum, and stash result */
- checksum = cksum(NULLHEADER,bp,len_p(bp));
- cp = &bp->data[2];
- cp = put16(cp,checksum);
-
- return bp;
- }
- /* Pull off ICMP header */
- int
- ntohicmp(icmp,bpp)
- struct icmp *icmp;
- struct mbuf **bpp;
- {
- char icmpbuf[8];
-
- if(icmp == (struct icmp *)NULL)
- return -1;
- if(pullup(bpp,icmpbuf,8) != 8)
- return -1;
- icmp->type = icmpbuf[0];
- icmp->code = icmpbuf[1];
- icmp->args.echo.id = get16(&icmpbuf[4]);
- icmp->args.echo.seq = get16(&icmpbuf[6]);
- return 0;
- }
-
-